//
//  LGCancerPatientDetailFollowCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/7/9.
//  患者详情-随访记录

#import "LGCancerPatientDetailFollowCell.h"

@interface LGCancerPatientDetailFollowCell()
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;

@end

@implementation LGCancerPatientDetailFollowCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.type = LGPositionTypeSingle;
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    [super setDataDic:dataDic];
    NSString *planName = LGNSString(dataDic[@"careplan_title"]);
    self.nameLabel.text = [planName isEmptyString]?@"":planName;
    CGFloat nameTop = [planName isEmptyString]?0:viewPix(15);
    [self.nameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(nameTop);
    }];
    
    NSString *checked = LGNSString(dataDic[@"is_checked"]);
    NSString *planDate = LGNSString(dataDic[@"next_careplan_date"]);
    self.dateLabel.text = (planDate.length>0)?[NSString stringWithFormat:@"下次随访 %@",planDate]:@"暂无随访计划";
    self.switchBtn.hidden = (planDate.length>0)?NO:YES;
    self.moreBtn.hidden = (planDate.length>0)?NO:YES;
    self.addButton.hidden = (planDate.length>0)?YES:NO;
    
    if ([planDate isEmptyString]) {
        //没有随访
        self.switchBtn.hidden = YES;
        self.auditBtn.hidden = YES;
    }else{
        //是否待审批
        self.switchBtn.hidden = [checked isEqualToString:@"1"]?NO:YES;
        self.auditBtn.hidden = [checked isEqualToString:@"1"]?YES:NO;
        NSString *title = [kRoleId isEqualToString:@"10"]?@"进入审核":@"待审核";
        [self.auditBtn setTitle:title forState:UIControlStateNormal];
    }
    
    CGFloat bottom = (planDate.length>0)?-viewPix(15):-viewPix(64);
    [self.dateLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.baseView).offset(bottom);
    }];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.moreBtn];
    [self.baseView addSubview:self.dateLabel];
    [self.baseView addSubview:self.switchBtn];
    [self.baseView addSubview:self.auditBtn];
    [self.baseView addSubview:self.addButton];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(8));
        make.centerY.equalTo(self.iconView);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(15));
        make.right.equalTo(self.baseView).offset(-viewPix(120));
        make.left.equalTo(self.titleLabel);
    }];
    [self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.iconView);
        make.width.equalTo(@(viewPix(100)));
        make.height.equalTo(@(viewPix(40)));
    }];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(15));
        make.bottom.equalTo(self.baseView).offset(-viewPix(64));
    }];
    [self.switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.bottom.equalTo(self.baseView).offset(-viewPix(5));
        make.width.equalTo(@(viewPix(92)));
        make.height.equalTo(@(viewPix(32)));
    }];
    [self.auditBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.switchBtn);
        make.width.equalTo(@(viewPix(92)));
        make.height.equalTo(@(viewPix(32)));
    }];
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.dateLabel.mas_bottom).offset(viewPix(12));
        make.left.equalTo(self.titleLabel);
        make.right.equalTo(self.baseView).offset(-viewPix(15));
        make.height.equalTo(@(viewPix(40)));
    }];
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"患者档案-癌症区头"]];
        _iconView.frame = CGRectMake(0, viewPix(16), viewPix(4), viewPix(16));
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"随访记录" colorString:@"#282828" textFont:LGFontWeight(18, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UIButton *)moreBtn{
    if(!_moreBtn){
        _moreBtn = [UIButton buttonWithTitle:@"更多" titleFont:LGFont(13) textColor:@"#909399" imageName:@"grayTip16"];
        _moreBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _moreBtn.bounds = CGRectMake(0, 0, viewPix(100), viewPix(40));
        [_moreBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:3];
    }
    return _moreBtn;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"" colorString:@"#909399" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _dateLabel;
}

-(UIButton *)switchBtn{
    if(!_switchBtn){
        _switchBtn = [UIButton buttonWithImage:@"患者档案-癌症开关" frame:CGRectZero];
    }
    return _switchBtn;
}

-(UIButton *)auditBtn{
    if(!_auditBtn){
        _auditBtn = [UIButton buttonWithTitle:@"进入审批" titleFont:LGFont(17) textColor:kThemeColor imageName:@""];
        [_auditBtn addBorder:kThemeColor lineWidth:1 cornerRidus:viewPix(16)];
        _auditBtn.hidden = YES;
    }
    return _auditBtn;
}

-(UIButton *)addButton{
    if(!_addButton){
        _addButton = [UIButton buttonWithTitle:@"  新增随访计划" titleFont:LGFont(17) textColor:kThemeColor imageName:@"themeAdd12"];
        [_addButton addBorder:kThemeColor lineWidth:1 cornerRidus:viewPix(20)];
    }
    return _addButton;
}

@end
